package com.abigdreamer.im.client.module.talk.cinema;

import com.abigdreamer.im.client.module.messageProcess.IMessageProcess;
import com.abigdreamer.im.client.module.messageProcess.config.MessageProcessConfig;
import com.abigdreamer.im.client.util.ClientUtils;
import com.abigdreamer.im.message.BaseMessage;

public class ClientReceivedMessageProcessManager {

	public static void processMessage(BaseMessage message) {
		int messageType = message.getMsgType();
		IMessageProcess process = getInstance().creatMessageProcess(messageType);
		process.processMessage(message);
	}
	
	private static ClientReceivedMessageProcessManager instance;
	private MessageProcessConfig config;

	private ClientReceivedMessageProcessManager() {
		config = ClientUtils.getMessageProcessConfig();
	}

	public static ClientReceivedMessageProcessManager getInstance() {

		if (null == instance) {
			instance = new ClientReceivedMessageProcessManager();
		}
		return instance;
	}

	public IMessageProcess creatMessageProcess(int messageType) {
		if (null == config) {
			config = ClientUtils.getMessageProcessConfig();
		}
		String processClass = config.getProcessClass(messageType);
		IMessageProcess process = null;
		try {
			process = (IMessageProcess) Class.forName(processClass).newInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return process;
	}
}
